//
//  HeightTableCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/4/5.
//

#import "HeightTableCell.h"
//#import <PYEchartsView.h>
//#import <PYOption.h>

#import "PYLineDemoOptions.h"

#import "CyclingRouteDetailModel.h"

@interface HeightTableCell ()

@property (nonatomic, strong) PYZoomEchartsView *kEchartView;;
//@property (nonatomic, strong) WKWebView *webView;
@property (weak, nonatomic) IBOutlet UILabel *typeLbl;
@property (weak, nonatomic) IBOutlet UILabel *typeDetailLbl;

@end

@implementation HeightTableCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 16;
    self.bgView.layer.masksToBounds = YES;
//    _kEchartView = [PYEchartsView ]
    _kEchartView = [[PYZoomEchartsView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 240)];
    _kEchartView.userInteractionEnabled = NO;
    _kEchartView.backgroundColor = UIColor.clearColor;
    _kEchartView.userInteractionEnabled = NO;
    [self.bgView addSubview:_kEchartView];

    
}

- (void)setHight:(Highly *)hight {
    _hight = hight;
    NSArray *x = hight.x;
    NSArray *y = hight.data;
    if(!x || x.count == 0) {
        x = @[@0];
    }
    if(!y || y.count == 0) {
        y = @[@0];
    }
    self.heightL.text = [NSString stringWithFormat:@"累计爬升%@",hight.climb];
    [_kEchartView setOption:[PYLineDemoOptions standardLineOptionWithX:x y:y]];
    [_kEchartView loadEcharts];
}

- (void)setHeightModel:(CyclingRouteHighlyModel *)heightModel
{
    NSArray *x = heightModel.x;
    NSArray *y = heightModel.data;
    if(!x || x.count == 0) {
        x = @[@0];
    }
    if(!y || y.count == 0) {
        y = @[@0];
    }
    [_kEchartView setOption:[PYLineDemoOptions standardLineOptionWithX:x y:y]];
    [_kEchartView loadEcharts];
    self.typeLbl.text = @"高度";
    self.typeDetailLbl.text = [NSString stringWithFormat:@"累计爬升%@", heightModel.climb];
}

- (void)setSpeedModel:(CyclingRouteSpeedModel *)speedModel
{
    NSArray *x = speedModel.x;
    NSArray *y = speedModel.data;
    if(!x || x.count == 0) {
        x = @[@0];
    }
    if(!y || y.count == 0) {
        y = @[@0];
    }
    [_kEchartView setOption:[PYLineDemoOptions standardLineOptionWithX:x y:y]];
    [_kEchartView loadEcharts];
    
    self.typeLbl.text = @"速度";
    self.typeDetailLbl.text = [NSString stringWithFormat:@"单位：%@", speedModel.unit];
}

- (void)setHeartModel:(CyclingRouteHeartModel *)heartModel
{
    NSArray *x = heartModel.x;
    NSArray *y = heartModel.data;
    if(!x || x.count == 0) {
        x = @[@0];
    }
    if(!y || y.count == 0) {
        y = @[@0];
    }
    [_kEchartView setOption:[PYLineDemoOptions standardLineOptionWithX:x y:y]];
    [_kEchartView loadEcharts];
    
    self.typeLbl.text = @"心率";
    self.typeDetailLbl.text = [NSString stringWithFormat:@"单位：%@", heartModel.unit];
}

#pragma mark 初始化图表
-(NSString *)dictToJson:(NSDictionary *)dict{
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonStr = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    return jsonStr;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
